package com.example;

import java.io.IOException;
import java.util.ArrayList;

import com.example.entity.Article;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/articleDetail")
@SuppressWarnings("unchecked")
public class AticleDetail extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int index = Integer.valueOf(req.getParameter("index"));
        System.out.println(index);
        ArrayList<Article> articles = (ArrayList<Article>)req.getSession().getAttribute("articles");
        Article article = articles.get(index);
        req.setAttribute("article", article);
        System.out.println(article.getTitle());
        req.getRequestDispatcher("/WEB-INF/jsp/articleDetail.jsp").forward(req, resp);;
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
